package com.chaoxing.controller;

import com.chaoxing.entity.User;
import com.chaoxing.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 用户注册
     * @param user
     * @return
     */
    @PostMapping("/register.do")
    public Map<String,String> receiveUserReg(User user){
        Map<String,String> map = new HashMap<>();
        int result = userService.insert(user);
        if(result == 1){
            map.put("msg","注册成功！");
            return map;
        }else {
            map.put("msg","注册失败!");
            return map;
        }
    }

    /**
     * 用户登录
     * @param name
     * @param pwd
     * @return
     */
    @PostMapping("/login.do")
    public Map<String,String> loginSys(String name, String pwd){
        Map<String,String> map = new HashMap<>();
        //登录校验
        Integer res = userService.loginSys(name, pwd);
        if(res == 1){
            map.put("msg","success");
            map.put("userName",name);
            return map;
        }else {
            map.put("msg","登录失败,请检查用户名和密码!");
            return map;
        }
    }
}
